//$Id$
function Cookie(){}
Cookie.get = function (key)  {
	var init = (document.cookie).indexOf(key);
	var cookielength = document.cookie.length;
        var value="";
	if(init != -1 )
    	{
    		var keylen = key.length;
    		beginIndex = (init+keylen);
    		value=(document.cookie).substr((beginIndex+1),cookielength);
                if(value.indexOf(";")!=-1){value=value.substring(0,value.indexOf(";"));}
	}	 
	return value;
}

Cookie.set = function (key,value,expiryTime) {
	var expDate = new Date();
        if(expiryTime==null || expiryTime==""){expiryTime=(30*24*60*60*1000);}        
        expDate.setTime(expDate.getTime()+expiryTime);        
	document.cookie=key+"= "+value+";expires= "+((expDate).toGMTString());
 	return true;
}

Cookie.remove = function(key){
 var cval=Cookie.get(key);
 if(cval!=""){
       var expDate = new Date();
       document.cookie=key+"=;expires= "+((expDate).toGMTString());
 }
 return cval;
}

Cookie.updateChat=function(chid){
 var openChats=Cookie.get("openchats"); 
 if(openChats!=""){
    openChats=openChats+":";
 }
 openChats=openChats+(""+chid);
 Cookie.set("openchats",openChats); 
}

Cookie.retainChats=function(){
 var expTime=(10*60*1000);
 var theme=Cookie.get("theme");
 Cookie.set("chatcount",""+CURCHATS.length,expTime);
 for(var c=0;c<CURCHATS.length;c++){
   if(theme=="desktop" && document.getElementById(CURCHATS[c])==null){continue;}
   else if(theme=="classic" && !Tab.isExists(CURCHATS[c])){continue;}
     Cookie.set("chat"+c,CURCHATS[c],expTime);
 }
}

Cookie.reopenChats=function(){
 if(!WebMessanger.registered || WebMessanger.registered == undefined){setTimeout("Cookie.reopenChats()",2000);return;}
 var chatcount=Cookie.remove("chatcount");
 if(chatcount==""){return;}
 for(var o=0;o<chatcount;o++){
     var chid=Cookie.remove("chat"+o);
     setTimeout("WebMessanger.joinchat('"+chid+"')",(o*300));
 }
}
